package com.codenjoy.calculator.base;


/**
 * Created by kate on 31.01.2015.
 */
public class BaseFactory {

    public static Base getBase(String baseSign) {
        if (RomanBase.ROMAN_BASE_SIGN.equalsIgnoreCase(baseSign)){
            return createRomanBase();
        }
        return createArabianBase(baseSign);
    }

    private static Base createArabianBase(String baseSign) {
        int baseNum = 0;
        try {
            baseNum = Integer.valueOf(baseSign);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Invalid base", e);
        }
        if (baseNum > ArabianBase.ARABIAN_SYSTEM_SYMBOLS.length() || baseNum <= 1) {
            throw new IllegalArgumentException("Invalid base");
        }
        return new ArabianBase(baseNum);
    }

    private static Base createRomanBase() {
        return new RomanBase();
    }
}
